package HuaWeiPractice;

import java.util.Scanner;

/**
 * created by ysy 2022/3/5 17:26
 * 写出一个程序，接受一个由字母、数字和空格组成的字符串，和一个字符，然后输出输入字符串中该字符的出现次数。（不区分大小写字母）
 *
 * @author 杨双洋
 * @version 1.0
 * @Email Yangsybd@163.com
 */
public class ExistWordIfInString {
    public static void main(String[] args) {
        System.out.println("请输入一个由字母、数字和空格组成的字符串：");
        Scanner sc = new Scanner(System.in);
        String inputString = sc.nextLine();
        String[] split = inputString.split("");
        System.out.println("请随意输入一个字符：");
        Scanner sc1 = new Scanner(System.in);
        String inputWord = sc1.nextLine();
        int count = 0;
        for (int i = 0; i < split.length; i++) {
            boolean equals = split[i].equalsIgnoreCase(inputWord);
            if (equals==true){
                count++;
            }
        }
        System.out.println("字符串" + inputWord + "共在字符串" + inputString + "中出现：" + count + "次");
    }
}
